#include <iostream>
#include <stdlib.h>

#define totalSize 40
#define maxSize 30
typedef struct{
    char data;
    int weight;
    int lchild,rchild,parent;
}HFNode;

typedef struct{
    HFTree elem[totalSize];
    int num;
    int root;
}HFTree;



void create(int a[],int n){
    HFTree Tree;
    int i,k,s1,s2;
    int min1,min2;
    for (int i=0;i<n;i++){
        Tree.elem[i].weight=a[i];
    }
    for (int i=0;i<n;i++){
        Tree.elem[i].lchild=-1;
        Tree.elem[i].rchild=-1;
        Tree.elem[i].parent=-1;
    }
    for (int i=n;i<2*n-1;i++){
        min1=min2=10000;
        s1=s2=0;
        for (k=0;k<i;k++){
            if (Tree.elem[k].parent==-1){
                if (Tree.elem[k].weight<min1){
                    min2=min1;
                    s2=s1;
                    min1=Tree.elem[k].weight;
                }else if(Tree.elem[k].weight<min2){
                   min2=Tree.elem[k].weight;
                   s2=k; 
                }

            }
        }
        Tree.elem[i].lchild=s1;
        Tree.elem[i].rchild=s2;
        Tree.elem[i].weight=Tree.elem[s1].weight+Tree.elem[s2].weight;
    }
    Tree.root=2*n-2;
    Tree.num=n;
}